package com.darrenchan.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-02-24 00:33
 */
public class Q257II {
    public List<String> binaryTreePaths(TreeNode root) {
        if(root == null) {
            return new ArrayList<>();
        }

        if(root.left == null && root.right == null) {
            List<String> results = new ArrayList<>();
            results.add(root.val + "");
            return results;
        }

        List<String> left = binaryTreePaths(root.left);
        List<String> right = binaryTreePaths(root.right);

        List<String> results = new ArrayList<>();
        for (String s : left) {
            results.add(root.val + "->" + s);
        }

        for (String s : right) {
            results.add(root.val + "->" + s);
        }

        return results;
    }
}
